#ifndef SESSIONMANAGER_H
#define SESSIONMANAGER_H

#include <QObject>
#include <QHash>
#include <QMutex>
#include <QMutexLocker>

#include <google/protobuf/message.h>

#include "commandconfig.h"
#include "session.h"
#include "type.h"
#include "systemconfig.h"
#include "exception.h"

namespace apollo
{
	namespace core
	{
		class SessionManager : public QObject
		{
			Q_OBJECT

				
		public:
			SessionManager(QObject *parent);
			~SessionManager();
		public:
			void init(QSharedPointer<SystemConfig> &config);
			void send(QString& commandName, MessagePtr msg);
			MessagePtr request(QString& commandName, MessagePtr request);
			MessagePtr login(MessagePtr request);
		private:
			QSharedPointer<Session> getSession(QString &connectionName, bool createNotExisted = true);
		private:
			QSharedPointer<SystemConfig> systemConfig;
			QHash<QString, QSharedPointer<Session> > sessions;
			//QMutex sessionLocker;
			MessagePtr loginRequest;
			MessagePtr loginResponse;

		};
	}}
#endif // SESSIONMANAGER_H
